package com.tanhua.server.controller;

import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.MovementVo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;


    /**
     * 通过动态id 查询评论列表查询
     * @return
     */
    @GetMapping
    public ResponseEntity findByUserId(@RequestParam(value = "page",defaultValue = "1") Long page,
                                       @RequestParam(value = "pageSize",defaultValue = "10") Long pageSize,
                                       String movementId){
        PageResult<CommentVo> commentVoPageResult = commentService.findByUserId(page,pageSize,movementId);
        return ResponseEntity.ok(commentVoPageResult);
    }

    /**
     * 发布评论
     * @param param
     * @return
     */
    @PostMapping
    public ResponseEntity comment(@RequestBody Map<String,String> param){
        String movementId = param.get("movementId");
        String comment = param.get("comment");
        commentService.comment(movementId,comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String commentId){

        Integer loveCount = commentService.like(commentId);
        return ResponseEntity.ok(loveCount);
    }


    /**
     * 评论取消点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String commentId){
        Integer likeCount = commentService.dislike(commentId);
        return ResponseEntity.ok(likeCount);
    }

}
